//
//  ReportViewController.m
//  HRJiWei
//
//  Created by zsj1992 on 16/12/12.
//  Copyright © 2016年 bjhj. All rights reserved.
//

#import "ReportViewController.h"
#import "ReportCategoryViewController.h"
#import "HJCategory.h"

#import "InformationViewController.h"

#import "HJReport.h"

#import "InfoViewController.h"

@interface ReportViewController ()<UITextViewDelegate,UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIButton *btnConfirm;
@property (weak, nonatomic) IBOutlet UIView *niticeView;
@property (weak, nonatomic) IBOutlet UILabel *lblPlaceholder;

@property (weak, nonatomic) IBOutlet UITextView *txtView;
@property (weak, nonatomic) IBOutlet UIView *categoryView;
@property (weak, nonatomic) IBOutlet UILabel *lblCategory;
@property (weak, nonatomic) IBOutlet UILabel *lblType;
@property (weak, nonatomic) IBOutlet UITextField *txtReportTitle;
@property (weak, nonatomic) IBOutlet UIView *reportType;
- (IBAction)NextClick:(id)sender;

@end

@implementation ReportViewController

static UIView * cover;
static HJReport * report;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    report = [[HJReport alloc]init];
    
    
    self.navigationItem.hidesBackButton = YES;
    [self.navigationController setNavigationBarHidden:YES];
    
    
    cover = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
    
    cover.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
    
    [self.view addSubview:cover];
    
    
    

    self.btnConfirm.layer.cornerRadius = 4;
    self.btnConfirm.layer.masksToBounds = YES;
    self.btnConfirm.layer.borderColor = [Tool colorWithHexString:@"#0086e1" alpha:1].CGColor;
    self.btnConfirm.layer.borderWidth = 1;

    
    UITapGestureRecognizer * categoryTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(categoryTap)];
    [self.categoryView addGestureRecognizer:categoryTap];
    UITapGestureRecognizer * reportTypeTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(reportTypeTap)];
    [self.reportType addGestureRecognizer:reportTypeTap];
    
    
    
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectCategory:) name:@"selectCategory" object:nil];
    
    
    
}

-(void)selectCategory:(NSNotification *)notification{

    HJCategory* category = notification.userInfo[@"category"];
    
    self.lblCategory.text = category.name;
    self.lblCategory.textColor = [UIColor blackColor];
    
    report.categoryId = category.ID;
    report.categoryName = category.name;
    
}


//点击了举报分类
-(void)categoryTap{

    [self loadData];
    
}


-(void)loadData{
    
    
    NSMutableArray * arrTemp = [NSMutableArray array];
    
    NSMutableDictionary * parameter = [NSMutableDictionary dictionary];
    [parameter setObject:@"0"  forKey:@"parentId"];
    
    [NetWork GET:getReportCategory parmater:parameter Block:^(NSData *data) {
        
        NSArray * arrDic = (NSArray *)data;
        for (NSDictionary * dic in arrDic) {
            HJCategory * category = [HJCategory mj_objectWithKeyValues:dic];
            [arrTemp addObject:category];
        }
        ReportCategoryViewController * categoryVc = [[ReportCategoryViewController alloc]init];

        categoryVc.catogories = arrTemp;
        
        [self.navigationController pushViewController:categoryVc animated:YES];

        
    }];
}





//点击了举报方式
-(void)reportTypeTap{
    
    
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"请选择举报方式"                                                                             message: nil                                                                       preferredStyle:UIAlertControllerStyleActionSheet];
    //添加Button
    [alertController addAction: [UIAlertAction actionWithTitle: @"匿名举报" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        //处理点击拍照
        self.lblType.text = @"匿名举报";
        self.lblType.textColor = [UIColor blackColor];

        report.reportStyle = @"0";
        
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"实名举报" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
        //处理点击从相册选取
        self.lblType.text = @"实名举报";
        self.lblType.textColor = [UIColor blackColor];
        report.reportStyle = @"1";
        
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    
    [self presentViewController: alertController animated: YES completion: nil];
    

    
    
    
}




-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.view bringSubviewToFront:self.niticeView];

}


-(void)textViewDidChange:(UITextView *)textView{
    
    if (self.txtView.text.length>0) {
        self.lblPlaceholder.hidden = YES;
    }else{
        self.lblPlaceholder.hidden = NO;
    }
    
    
    
    
    
}


//点击确认
- (IBAction)confirm:(id)sender {
    
    [self.niticeView removeFromSuperview];
    [cover removeFromSuperview];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    [self.view endEditing:YES];

    return YES;
}

- (IBAction)NextClick:(id)sender {
    
    HJReport * report = [[HJReport alloc]init];

//    if ([self.lblCategory.text isEqualToString:@"举报分类"]) {
//        [Tool ShowpromptWithMsg:@"请选择举报分类"];
//        return;
//    }else if([Tool isBlankString:self.txtReportTitle.text]){
//    
//        [Tool ShowpromptWithMsg:@"举报标题不能为空"];
//        return;
//    }else if (self.txtView.text.length<20){
//    
//        [Tool ShowpromptWithMsg:@"举报内容不能少于20字"];
//        return;
//    }else if ([self.lblType.text isEqualToString:@"举报方式"]){
//    
//        [Tool ShowpromptWithMsg:@"请选择举报方式"];
//        return;
//        
//    }
    
    


    report.reportTitle = self.txtReportTitle.text;
    report.reportContent = self.txtView.text;
    

    
    
    
    
    
    
    
    
    
    InfoViewController * infoVc = [[InfoViewController alloc]init];
    
    
    
    
    
//    InformationViewController * informationVc = [[InformationViewController alloc]init];
    infoVc.report = report;
    
    if ([self.lblType.text isEqualToString:@"匿名举报"]) {
        
        infoVc.visible = NO;
    }else{
        infoVc.visible = YES;
    }
    [self.navigationController pushViewController:infoVc animated:YES];
    
}
@end
